import Vue from 'vue'
import VueRouter from 'vue-router'
import Film from '@/views/Film.vue'
import Nowplaying from '@/views/Film/Nowplaying.vue'
import Comingsoon from '@/views/Film/Comingsoon.vue'
import Center from '@/views/Center.vue'
import Cinema from '@/views/Cinema.vue'
import Information from '@/views/Information.vue'
import Detail from '@/views/Detail.vue'
import Login from '@/views/Login.vue'
import City from '@/views/City.vue'

Vue.use(VueRouter)

const routes = [{
  path: '/film',
  name: 'Film',
  component: Film,
  children: [{
    path: 'nowplaying',
    name: 'Nowplaying',
    component: Nowplaying
  },
  {
    path: 'comingsoon',
    name: 'Comingsoon',
    component: Comingsoon
  },
  {
    path: '',
    redirect: '/film/nowplaying'
  }
  ]
},
{
  path: '/cinema',
  name: 'Cinema',
  component: Cinema
},
{
  path: '/information',
  name: 'Information',
  component: Information
},
{
  // 动态路由传参
  path: '/detail/:myid',
  name: 'Detail',
  component: Detail
},
{
  path: '/login',
  name: 'Login',
  component: Login
},
{
  path: '/center',
  name: 'Center',
  component: Center
},
{
  path: '/city',
  name: 'City',
  component: City
},
{
  path: '*',
  redirect: '/film'
}
  // {
  //   path: '/about',
  //   name: 'About',
  //   // route level code-splitting
  //   // this generates a separate chunk (about.[hash].js) for this route
  //   // which is lazy-loaded when the route is visited.
  //   component: function () {
  //     return import(/* webpackChunkName: "about" */ '../views/About.vue')
  //   }
  // }
]

const router = new VueRouter({
  // mode: 'history',
  base: process.env.BASE_URL,
  routes
})
// // 创建路由守卫判断逻辑
// const auth = {
//   isLogin () {
//     return false
//   }
// }
// // 路由全局守卫
// router.beforeEach((to, from, next) => {
//   if (to.path === '/center') {
//     console.log('路由守卫，未登录不允许进入center页面')
//     if (auth.isLogin()) {
//       next()
//     } else {
//       next('/login')
//     }
//   } else {
//     next()
//   }
// })
export default router
